package com.ruoyi.controller.admin.crop;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.admin.AdminCropDB;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.admin.AdminCropService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/admin/crop")
public class AdminCropController extends BaseController {
    @Resource
    private AdminCropService adminCropService;

    /**
     * 查询后台-作物品种列表
     */
    @PreAuthorize("@ss.hasPermi('crop:crop:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdminCropDB AdminCropDB) {
        return adminCropService.selectAdminCropDBList(AdminCropDB);
    }

    /**
     * 导出后台-作物品种列表
     */
    @PreAuthorize("@ss.hasPermi('crop:crop:export')")
    @Log(title = "后台-作物品种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdminCropDB AdminCropDB) {
        List<AdminCropDB> list = (List<AdminCropDB>)adminCropService.selectAdminCropDBList(AdminCropDB).getRows();
        ExcelUtil<AdminCropDB> util = new ExcelUtil<AdminCropDB>(AdminCropDB.class);
        util.exportExcel(response, list, "后台-作物品种数据");
    }

    /**
     * 获取后台-作物品种详细信息
     */
    @PreAuthorize("@ss.hasPermi('crop:crop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(adminCropService.selectAdminCropDBById(id));
    }

    /**
     * 新增后台-作物品种
     */
    @PreAuthorize("@ss.hasPermi('crop:crop:add')")
    @Log(title = "后台-作物品种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdminCropDB AdminCropDB) {
        return toAjax(adminCropService.insertAdminCropDB(AdminCropDB));
    }

    /**
     * 修改后台-作物品种
     */
    @PreAuthorize("@ss.hasPermi('crop:crop:edit')")
    @Log(title = "后台-作物品种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdminCropDB AdminCropDB) {
        return toAjax(adminCropService.updateAdminCropDB(AdminCropDB));
    }


    /**
     * 查询后台-作物品种列表
     */
    @PreAuthorize("@ss.hasPermi('crop:crop:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll() {
        return AjaxResult.success(adminCropService.listAll());
    }



    /**
     * 删除后台-作物品种
     */
//    @PreAuthorize("@ss.hasPermi('crop:crop:remove')")
//    @Log(title = "后台-作物品种", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids) {
//        return toAjax(adminCropService.deleteAdminCropDBByIds(ids));
//    }


}
